﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jizsoft.JFrame.Result
{
    public class ListResult<T> : ServiceResult
    {
        public ListResultData<T> Data { get; private set; }

        /// <summary>
        /// 构建一个没有错误的结果
        /// </summary>
        /// <param name="data"></param>
        public ListResult(List<T> items)
            : base()
        {
            Data = new ListResultData<T>(items);
            IsSuccess = true;
            ErrorCode = 0;
            Message = string.Empty;
        }

        /// <summary>
        /// 构建一个错误的结果
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="message"></param>
        public ListResult(int errorCode, string message)
        {
            IsSuccess = false;
            ErrorCode = errorCode;
            Message = message;
        }
    }

    public class ListResultData<T>
    {
        public int Count { get; set; }
        public List<T> Items { get; set; }

        public ListResultData(List<T> items)
            : base()
        {
            Items = items;
            Count = items.Count;
        }
    }
}
